﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace SAEA_TestServer.Server
{
    /// <summary>
    /// 异步连接对象池
    /// </summary>
    public class SAEA_AsnySocketPool
    {
        private readonly Queue<SocketAsyncEventArgs> SAEA_Queue; 

        /// <summary>
        /// 构造函数中设定最大异步对象池
        /// </summary>
        /// <param name="maxClientCount"></param>
        public SAEA_AsnySocketPool(int maxClientCount)
        {
            SAEA_Queue = new Queue<SocketAsyncEventArgs>(maxClientCount);
        }
        
        /// <summary>
        /// 添加异步对象到队列中
        /// </summary>
        /// <param name="saea"></param>
        public void Push(SocketAsyncEventArgs saea)
        {
            SAEA_Queue.Enqueue(saea);
        }

        /// <summary>
        /// 返回第一个异步对象，并从列表中移除
        /// </summary>
        /// <returns></returns>
        public SocketAsyncEventArgs Pop()
        {
            return SAEA_Queue.Dequeue();
        }
    }
}
